﻿/*
 * Authors:
 *   钟峰(Popeye Zhong) <9555843@qq.com>
 *
 * Copyright (c) 2017 Flagwind Game Studio. All rights reserved.
 */

using System;
using System.Collections.Generic;

namespace Flagwind.Gaming.Triplets
{
	/// <summary>
	/// 表示“诈金花”的发牌器类。
	/// </summary>
    public class TripletDealer : IGameDealer
    {
		#region 常量定义
		private const byte DECK_COUNT = 52;
		#endregion

		#region 单例字段
		public static readonly TripletDealer Default = new TripletDealer();
		#endregion

		#region 私有方法
		private TripletDealer()
		{
		}
		#endregion

		#region 公共方法
		/// <summary>
		/// 发牌方法。
		/// </summary>
		/// <param name="count">指定要发牌的人数。</param>
		/// <returns>返回由<paramref name="count"/>参数指定人数的牌手集。</returns>
		public ArraySegment<byte>[] Deal(int count)
		{
			if(count < 1 || count > 16)
				throw new ArgumentOutOfRangeException(nameof(count));

			//开局洗牌
			var cards = Shuffler.Shuffle(DECK_COUNT);

			//创建指定数量的牌手数
			var hands = new ArraySegment<byte>[count];

			for(var i = 0; i < count; i++)
			{
				//从洗好的牌堆中依次抽取三张作为一手“诈金花”牌
				hands[i] = new ArraySegment<byte>(cards, i * 3, 3);
			}

			return hands;
		}
		#endregion
	}
}
